package com.pkdl.forms;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;

import com.pkdl.dao.BenhNhanChoKhamDAO;
import com.pkdl.dao.BenhNhanDAO;
import com.pkdl.dao.DichVuDAO;
import com.pkdl.dao.PhieuKhamDAO;
import com.pkdl.dao.PhieuKham_DichVuDAO;
import com.pkdl.dao.PhieuKham_ThuocDAO;
import com.pkdl.dao.ThuocDAO;
import com.pkdl.datepicker.JCalendar;
import com.pkdl.dto.BenhNhanChoKhamDTO;
import com.pkdl.dto.BenhNhanDTO;
import com.pkdl.dto.DichVuDTO;
import com.pkdl.dto.PhieuKhamDTO;
import com.pkdl.dto.PhieuKham_DichVuDTO;
import com.pkdl.dto.PhieuKham_ThuocDTO;
import com.pkdl.dto.ThuocDTO;
import com.pkdl.helpers.CommonVars;
import com.pkdl.helpers.SorterByName;
import com.pkdl.tables.TableCapNhatThemDichVu;
import com.pkdl.tables.TableCapNhatThemThuoc;

@SuppressWarnings("serial")
public class DlgCapNhatPhieuKham extends JDialog {
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			DlgCapNhatPhieuKham dialog = new DlgCapNhatPhieuKham(null, true);
			dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private JTextField txtMaBenhNhan;
	private JTextField txtTenBenhNhan;
	private JTextField txtNguoiLap;
	private JTextField txtNgayLap;
	private JTable tblDanhSachDichVu;
	private JComboBox cbxDichVu;
	private JComboBox cbxThuoc;

	private JTable tblDanhSachThuoc;
	public int MaBenhNhan = -1;
	public int MaPhieuKham = -1;
	public Timestamp ThoiDiemTiepNhan;
	private BenhNhanChoKhamDAO bnckDAO;
	private BenhNhanDAO bnDAO;
	private DichVuDAO dvDAO;
	private ThuocDAO tDAO;
	private List<PhieuKham_DichVuDTO> lstPhieuKhamDichVu;
	private TableCapNhatThemDichVu tblDichVu;
	private List<PhieuKham_ThuocDTO> lstPhieuKhamThuoc;
	private TableCapNhatThemThuoc tblThuoc;
	private PhieuKhamDAO pkDAO;
	private PhieuKham_DichVuDAO pkdvDAO;
	private PhieuKham_ThuocDAO pktDAO;
	private JCalendar txtNgayTaiKham = null;
	private JPanel pnlNgayTaiKham;
	private JTextArea txtKetLuanChung;
	private JTextArea txtGhiChu;

	/**
	 * Create the dialog.
	 */
	public DlgCapNhatPhieuKham(Frame parent, boolean modal) {
		super(parent, modal);
		this.setTitle("lap phieu kham");
		this.setBounds(100, 100, 1095, 703);
		this.setLocationRelativeTo(null);
		this.getContentPane().setLayout(new BorderLayout(0, 0));

		JSplitPane splitPane = new JSplitPane();
		this.getContentPane().add(splitPane, BorderLayout.CENTER);

		JPanel panel = new JPanel();
		panel.setPreferredSize(new Dimension(350, 10));
		splitPane.setLeftComponent(panel);
		panel.setLayout(new BorderLayout(0, 0));

		JPanel panel_3 = new JPanel();
		panel.add(panel_3, BorderLayout.CENTER);
		panel_3.setLayout(null);

		JLabel lblMBnhNhn = new JLabel("M\u00E3 b\u1EC7nh nh\u00E2n");
		lblMBnhNhn.setBounds(10, 14, 85, 14);
		panel_3.add(lblMBnhNhn);

		this.txtMaBenhNhan = new JTextField();
		this.txtMaBenhNhan.setEditable(false);
		this.txtMaBenhNhan.setColumns(10);
		this.txtMaBenhNhan.setBounds(105, 11, 235, 20);
		panel_3.add(this.txtMaBenhNhan);

		JLabel lblTnBnhNhn = new JLabel("T\u00EAn b\u1EC7nh nh\u00E2n");
		lblTnBnhNhn.setBounds(10, 42, 85, 14);
		panel_3.add(lblTnBnhNhn);

		this.txtTenBenhNhan = new JTextField();
		this.txtTenBenhNhan.setEditable(false);
		this.txtTenBenhNhan.setColumns(10);
		this.txtTenBenhNhan.setBounds(105, 39, 235, 20);
		panel_3.add(this.txtTenBenhNhan);

		JLabel lblNgiLpPhiu = new JLabel("Ng\u01B0\u1EDDi l\u1EADp");
		lblNgiLpPhiu.setBounds(10, 70, 85, 14);
		panel_3.add(lblNgiLpPhiu);

		this.txtNguoiLap = new JTextField();
		this.txtNguoiLap.setEditable(false);
		this.txtNguoiLap.setColumns(10);
		this.txtNguoiLap.setBounds(105, 67, 235, 20);
		panel_3.add(this.txtNguoiLap);

		JLabel lblNgyLpPhiu = new JLabel("Ng\u00E0y l\u1EADp");
		lblNgyLpPhiu.setBounds(10, 98, 85, 14);
		panel_3.add(lblNgyLpPhiu);

		this.txtNgayLap = new JTextField();
		this.txtNgayLap.setEditable(false);
		this.txtNgayLap.setColumns(10);
		this.txtNgayLap.setBounds(105, 95, 235, 20);
		panel_3.add(this.txtNgayLap);

		JPanel panel_1 = new JPanel();
		splitPane.setRightComponent(panel_1);
		panel_1.setLayout(new BorderLayout(0, 0));

		JPanel panel_2 = new JPanel();
		panel_2.setPreferredSize(new Dimension(10, 32));
		panel_1.add(panel_2, BorderLayout.NORTH);

		JLabel lblLpPhiuKhm = new JLabel(
				"C\u1EADp nh\u1EADt phi\u1EBFu kh\u00E1m");
		lblLpPhiuKhm.setForeground(new Color(0, 128, 0));
		lblLpPhiuKhm.setFont(new Font("Tahoma", Font.BOLD, 18));
		panel_2.add(lblLpPhiuKhm);

		JPanel panel_4 = new JPanel();
		panel_1.add(panel_4, BorderLayout.CENTER);
		panel_4.setLayout(null);

		JLabel lblDanhSchDch = new JLabel("Danh s\u00E1ch d\u1ECBch v\u1EE5");
		lblDanhSchDch.setBounds(10, 15, 109, 14);
		panel_4.add(lblDanhSchDch);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 45, 710, 140);
		panel_4.add(scrollPane);

		this.tblDanhSachDichVu = new JTable();
		this.tblDanhSachDichVu.setModel(new DefaultTableModel(
				new Object[][] {}, new String[] { "New column", "New column",
						"New column", "New column" }));
		this.tblDanhSachDichVu.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent evt) {
				DlgCapNhatPhieuKham.this.tblDanhSachDichVuMousePressed(evt);
			}
		});
		scrollPane.setViewportView(this.tblDanhSachDichVu);

		JButton btnThemDichVu = new JButton("Th\u00EAm m\u1EDBi");
		btnThemDichVu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (!DlgCapNhatPhieuKham.this.isExistInListDichVu()) {
					DlgCapNhatThemDichVu dlg = new DlgCapNhatThemDichVu(null,
							true);
					dlg.DichVuStr = (String) DlgCapNhatPhieuKham.this.cbxDichVu
							.getSelectedItem();
					dlg.loadThongTin();
					dlg.show();
					if (!dlg.KetLuan.equals("")) {
						DlgCapNhatPhieuKham.this.themDichVu(dlg.KetLuan);
					}
				}
			}
		});
		btnThemDichVu.setIcon(new ImageIcon(DlgCapNhatPhieuKham.class
				.getResource("/com/pkdl/resources/81.png")));
		btnThemDichVu.setBounds(492, 11, 112, 23);
		panel_4.add(btnThemDichVu);

		JButton btnXoaDichVu = new JButton("X\u00F3a");
		btnXoaDichVu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				DlgCapNhatPhieuKham.this.removeDichVu();
			}
		});
		btnXoaDichVu.setIcon(new ImageIcon(DlgCapNhatPhieuKham.class
				.getResource("/com/pkdl/resources/001_29.png")));
		btnXoaDichVu.setBounds(614, 11, 89, 23);
		panel_4.add(btnXoaDichVu);

		JLabel lblDanhSchThuc = new JLabel("Danh s\u00E1ch thu\u1ED1c");
		lblDanhSchThuc.setBounds(10, 205, 109, 14);
		panel_4.add(lblDanhSchThuc);

		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(10, 230, 710, 140);
		panel_4.add(scrollPane_1);

		this.tblDanhSachThuoc = new JTable();
		this.tblDanhSachThuoc.setModel(new DefaultTableModel(new Object[][] {},
				new String[] { "New column", "New column", "New column",
						"New column" }));
		this.tblDanhSachThuoc.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent evt) {
				DlgCapNhatPhieuKham.this.tblDanhSachThuocMousePressed(evt);
			}
		});
		scrollPane_1.setViewportView(this.tblDanhSachThuoc);

		JButton btnThemThuoc = new JButton("Th\u00EAm m\u1EDBi");
		btnThemThuoc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (!DlgCapNhatPhieuKham.this.isExistInListThuoc()) {
					DlgCapNhatThemThuoc dlg = new DlgCapNhatThemThuoc(null,
							true);
					dlg.ThuocStr = (String) DlgCapNhatPhieuKham.this.cbxThuoc
							.getSelectedItem();
					dlg.loadThongTin();
					dlg.show();
					if (dlg.SoLuong > 0) {
						DlgCapNhatPhieuKham.this.themThuoc(dlg.SoLuong);
					}
				}
			}
		});
		btnThemThuoc.setIcon(new ImageIcon(DlgCapNhatPhieuKham.class
				.getResource("/com/pkdl/resources/81.png")));
		btnThemThuoc.setBounds(492, 196, 112, 23);
		panel_4.add(btnThemThuoc);

		JButton btnXoaThuoc = new JButton("X\u00F3a");
		btnXoaThuoc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				DlgCapNhatPhieuKham.this.removeThuoc();
			}
		});
		btnXoaThuoc.setIcon(new ImageIcon(DlgCapNhatPhieuKham.class
				.getResource("/com/pkdl/resources/001_29.png")));
		btnXoaThuoc.setBounds(614, 196, 89, 23);
		panel_4.add(btnXoaThuoc);

		JButton btnLapPhieu = new JButton("C\u1EADp nh\u1EADt");
		btnLapPhieu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DlgCapNhatPhieuKham.this.capNhatPhieuKham();
			}
		});
		btnLapPhieu.setIcon(new ImageIcon(DlgCapNhatPhieuKham.class
				.getResource("/com/pkdl/resources/45.png")));
		btnLapPhieu.setBounds(591, 591, 112, 23);
		panel_4.add(btnLapPhieu);

		this.cbxDichVu = new JComboBox(new Object[] {});
		this.cbxDichVu.setBounds(129, 12, 335, 20);
		panel_4.add(this.cbxDichVu);

		this.cbxThuoc = new JComboBox(new Object[] {});
		this.cbxThuoc.setBounds(129, 199, 335, 20);
		panel_4.add(this.cbxThuoc);

		JLabel lblKet = new JLabel("K\u1EBFt lu\u1EADn chung");
		lblKet.setBounds(10, 381, 109, 14);
		panel_4.add(lblKet);

		this.txtKetLuanChung = new JTextArea();
		this.txtKetLuanChung.setBounds(10, 400, 460, 74);
		panel_4.add(this.txtKetLuanChung);

		JLabel lblNgyTiKhm = new JLabel("Ng\u00E0y t\u00E1i kh\u00E1m");
		lblNgyTiKhm.setBounds(493, 381, 109, 14);
		panel_4.add(lblNgyTiKhm);

		this.pnlNgayTaiKham = new JPanel();
		this.pnlNgayTaiKham.setBounds(493, 400, 227, 180);
		panel_4.add(this.pnlNgayTaiKham);
		this.pnlNgayTaiKham.setLayout(new BorderLayout(0, 0));

		this.txtGhiChu = new JTextArea();
		this.txtGhiChu.setBounds(10, 504, 460, 74);
		panel_4.add(this.txtGhiChu);

		JLabel label_1 = new JLabel("Ghi ch\u00FA");
		label_1.setBounds(10, 485, 109, 14);
		panel_4.add(label_1);
	}

	/**
	 * Lap phieu kham benh
	 */
	private void capNhatPhieuKham() {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MONTH, this.txtNgayTaiKham.getMonthChooser()
				.getMonth());
		cal.set(Calendar.DATE, this.txtNgayTaiKham.getDayChooser().getDay());
		cal.set(Calendar.YEAR, this.txtNgayTaiKham.getYearChooser().getYear());

		// Select PhieuKham de cap nhat
		this.pkDAO = new PhieuKhamDAO();
		PhieuKhamDTO pk = this.pkDAO.selectById(this.MaPhieuKham);

		if (pk == null) {
			JOptionPane.showMessageDialog(null, "Cap nhat phieu kham that bai",
					"Announcement", JOptionPane.ERROR_MESSAGE);
			return;
		}

		pk.setKetLuanChung(this.txtKetLuanChung.getText());
		pk.setGhiChu(this.txtGhiChu.getText());
		pk.setNgayTaiKham(cal.getTime());

		// Cap nhat phieu kham thanh cong
		if (this.pkDAO.update(pk)) {
			// Remove nhung cai cu truoc
			this.pkdvDAO = new PhieuKham_DichVuDAO();
			this.pktDAO = new PhieuKham_ThuocDAO();

			// Cap nhat lai danh sach dich vu
			if (this.pkdvDAO.deleteByMaPhieuKham(this.MaPhieuKham)) {
				for (PhieuKham_DichVuDTO element : this.lstPhieuKhamDichVu) {
					element.setMaPhieuKham(this.MaPhieuKham);
					this.pkdvDAO = new PhieuKham_DichVuDAO();
					this.pkdvDAO.insert(element);
				}
			}

			// Cap nhat lai danh sach thuoc
			if (this.pktDAO.deleteByMaPhieuKham(this.MaPhieuKham)) {
				for (PhieuKham_ThuocDTO element : this.lstPhieuKhamThuoc) {
					element.setMaPK(this.MaPhieuKham);
					this.pktDAO = new PhieuKham_ThuocDAO();
					this.pktDAO.insert(element);
				}
			}

			// Show message
			JOptionPane.showMessageDialog(null,
					"Cap nhat phieu kham thanh cong", "Announcement",
					JOptionPane.INFORMATION_MESSAGE);
			this.dispose();
		} else {
			JOptionPane.showMessageDialog(null, "Cap nhat phieu kham that bai",
					"Announcement", JOptionPane.ERROR_MESSAGE);
		}
	}

	/**
	 * Init data model for 2 tables
	 */
	public void initTables() {
		// Load danh sach dich vu trong phieu kham
		this.pkdvDAO = new PhieuKham_DichVuDAO();
		this.lstPhieuKhamDichVu = this.pkdvDAO
				.selectByMaPhieuKham(this.MaPhieuKham);
		// Load danh sach thuoc trong phieu kham
		this.pktDAO = new PhieuKham_ThuocDAO();
		this.lstPhieuKhamThuoc = this.pktDAO.selectByMaPK(this.MaPhieuKham);

		// Binding to table DichVu
		this.tblDichVu = new TableCapNhatThemDichVu(this.lstPhieuKhamDichVu);
		this.tblDichVu.loadDataIntoTable(this.tblDanhSachDichVu);

		// Binding to table Thuoc
		this.tblThuoc = new TableCapNhatThemThuoc(this.lstPhieuKhamThuoc);
		this.tblThuoc.loadDataIntoTable(this.tblDanhSachThuoc);

		// Update Phieu kham
		this.pkDAO = new PhieuKhamDAO();
		PhieuKhamDTO dto = this.pkDAO.selectById(this.MaPhieuKham);
		if (dto != null) {
			this.txtKetLuanChung.setText(dto.getKetLuanChung());
			this.txtGhiChu.setText(dto.getGhiChu());
			this.txtNgayTaiKham.setDate(dto.getNgayTaiKham());
		}
	}

	private boolean isExistInListDichVu() {
		String strItem = (String) this.cbxDichVu.getSelectedItem();

		String[] compVal = strItem.split("-");
		int maDV = Integer.parseInt(compVal[0].trim());

		boolean existent = false;

		for (PhieuKham_DichVuDTO item : this.lstPhieuKhamDichVu) {
			if (item.getMaDichVu() == maDV) {
				existent = true;
			}
		}

		if (existent) {
			return true;
		}

		return false;
	}

	private boolean isExistInListThuoc() {
		String strItem = (String) this.cbxThuoc.getSelectedItem();

		String[] compVal = strItem.split("-");
		int maThuoc = Integer.parseInt(compVal[0].trim());

		boolean existent = false;

		for (PhieuKham_ThuocDTO item : this.lstPhieuKhamThuoc) {
			if (item.getMaThuoc() == maThuoc) {
				existent = true;
			}
		}

		if (existent) {
			return true;
		}

		return false;
	}

	/**
	 * Tao calendar ngay sinh
	 */
	public void LoadCalendar() {
		if (this.txtNgayTaiKham == null) {
			this.txtNgayTaiKham = new JCalendar();
			this.pnlNgayTaiKham.add(this.txtNgayTaiKham);
		}
	}

	/**
	 * Load danh sach benh nhan
	 */
	public void loadDichVu() {
		this.cbxDichVu.removeAllItems();
		this.dvDAO = new DichVuDAO();
		List<DichVuDTO> ds = this.dvDAO.selectAll();
		Collections.sort(ds, new SorterByName());
		for (DichVuDTO element : ds) {
			this.cbxDichVu.addItem(String.valueOf(element.getMaDichVu())
					+ " - " + element.getTenDichVu());
		}
	}

	/**
	 * Load thong tin benh nhan
	 */
	public void loadThongTinBenhNhan() {
		if (this.MaBenhNhan != -1) {
			this.bnckDAO = new BenhNhanChoKhamDAO();
			this.bnDAO = new BenhNhanDAO();
			BenhNhanChoKhamDTO item = this.bnckDAO.selectById(this.MaBenhNhan);
			BenhNhanDTO dto = this.bnDAO.selectById(this.MaBenhNhan);
			item.setBenhNhan(dto);
			if (item != null) {
				this.txtMaBenhNhan.setText(String.valueOf(this.MaBenhNhan));
				this.txtTenBenhNhan.setText(item.getBenhNhan().getHoTen());
				this.txtNgayLap.setText(new SimpleDateFormat(
						"dd/MM/yyyy HH:mm:ss").format(item
						.getThoiDiemTiepNhan()));
				this.txtNguoiLap.setText(CommonVars.g_oNguoiDung.getHoTen());
			}
		}
	}

	/**
	 * Load danh sach benh nhan
	 */
	public void loadThuoc() {
		this.cbxThuoc.removeAllItems();
		this.tDAO = new ThuocDAO();
		List<ThuocDTO> ds = this.tDAO.selectAll();
		Collections.sort(ds, new SorterByName());
		for (ThuocDTO element : ds) {
			this.cbxThuoc.addItem(String.valueOf(element.getMaThuoc()) + " - "
					+ element.getTenThuoc());
		}
	}

	private void removeDichVu() {
		if (this.tblDanhSachDichVu.getSelectedRow() == -1) {
			return;
		}

		if (this.tblDanhSachDichVu.getValueAt(
				this.tblDanhSachDichVu.getSelectedRow(), 1) == null) {
			return;
		}

		this.lstPhieuKhamDichVu.remove(this.tblDanhSachDichVu.getSelectedRow());
		this.tblDichVu.refreshTable();
	}

	private void removeThuoc() {
		if (this.tblDanhSachThuoc.getSelectedRow() == -1) {
			return;
		}

		if (this.tblDanhSachThuoc.getValueAt(
				this.tblDanhSachThuoc.getSelectedRow(), 1) == null) {
			return;
		}

		this.lstPhieuKhamThuoc.remove(this.tblDanhSachThuoc.getSelectedRow());
		this.tblThuoc.refreshTable();
	}

	/**
	 * Xu ly su kien mousepressed
	 * 
	 * @param evt
	 */
	private void tblDanhSachDichVuMousePressed(java.awt.event.MouseEvent evt) {
		int modifiers = evt.getModifiers();
		if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
			if (this.tblDanhSachDichVu.getSelectedRow() == -1) {
				return;
			}

			if (this.tblDanhSachDichVu.getValueAt(
					this.tblDanhSachDichVu.getSelectedRow(), 1) == null) {
				return;
			}
			if (evt.getClickCount() == 2) {
				String maDichVu = this.tblDanhSachDichVu.getValueAt(
						this.tblDanhSachDichVu.getSelectedRow(), 1).toString();
				String tenDichVu = this.tblDanhSachDichVu.getValueAt(
						this.tblDanhSachDichVu.getSelectedRow(), 2).toString();
				String ketLuan = this.tblDanhSachDichVu.getValueAt(
						this.tblDanhSachDichVu.getSelectedRow(), 3).toString();

				DlgCapNhatThemDichVu dlg = new DlgCapNhatThemDichVu(null, true);
				dlg.MaDichVu = maDichVu;
				dlg.TenDichVu = tenDichVu;
				dlg.KetLuan = ketLuan;
				dlg.loadThongTin2();
				dlg.show();
				this.tblDanhSachDichVu.setValueAt(dlg.KetLuan,
						this.tblDanhSachDichVu.getSelectedRow(), 3);
			}
		}
	}

	private void tblDanhSachThuocMousePressed(java.awt.event.MouseEvent evt) {
		int modifiers = evt.getModifiers();
		if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
			if (this.tblDanhSachThuoc.getSelectedRow() == -1) {
				return;
			}

			if (this.tblDanhSachThuoc.getValueAt(
					this.tblDanhSachThuoc.getSelectedRow(), 1) == null) {
				return;
			}
			if (evt.getClickCount() == 2) {
				String maThuoc = this.tblDanhSachThuoc.getValueAt(
						this.tblDanhSachThuoc.getSelectedRow(), 1).toString();
				String tenThuoc = this.tblDanhSachThuoc.getValueAt(
						this.tblDanhSachThuoc.getSelectedRow(), 2).toString();
				String soluong = this.tblDanhSachThuoc.getValueAt(
						this.tblDanhSachThuoc.getSelectedRow(), 3).toString();

				DlgCapNhatThemThuoc dlg = new DlgCapNhatThemThuoc(null, true);
				dlg.MaThuoc = maThuoc;
				dlg.TenThuoc = tenThuoc;
				dlg.SoLuong = Integer.parseInt(soluong);
				dlg.loadThongTin2();
				dlg.show();
				this.tblDanhSachThuoc.setValueAt(dlg.SoLuong,
						this.tblDanhSachThuoc.getSelectedRow(), 3);
			}
		}
	}

	/**
	 * Them dich vu vao danh sach
	 */
	private void themDichVu(String ketluan) {
		if (!this.isExistInListDichVu()) {
			String strItem = (String) this.cbxDichVu.getSelectedItem();

			String[] compVal = strItem.split("-");
			int maDV = Integer.parseInt(compVal[0].trim());
			String tenDV = compVal[1].trim();

			PhieuKham_DichVuDTO dto = new PhieuKham_DichVuDTO();
			dto.setMaDichVu(maDV);
			dto.setTenDichVu(tenDV);
			dto.setKetLuan(ketluan);

			this.lstPhieuKhamDichVu.add(dto);
			this.tblDichVu.refreshTable();
		}

	}

	/**
	 * Them thuoc vao danh sach
	 */
	private void themThuoc(int soluong) {
		if (!this.isExistInListThuoc()) {
			String strItem = (String) this.cbxThuoc.getSelectedItem();

			String[] compVal = strItem.split("-");
			int maThuoc = Integer.parseInt(compVal[0].trim());
			String tenThuoc = compVal[1].trim();

			PhieuKham_ThuocDTO dto = new PhieuKham_ThuocDTO();
			dto.setMaThuoc(maThuoc);
			dto.setTenThuoc(tenThuoc);
			dto.setSoLuong(soluong);

			this.lstPhieuKhamThuoc.add(dto);
			this.tblThuoc.refreshTable();
		}

	}
}
